package com.colin.commentservice.exception;

import com.colin.response.R;
import com.colin.response.RCM;
import com.colin.commentservice.exception.sub.VideoNotExistException;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.sql.SQLException;
public class GlobalException {

    @ExceptionHandler(AccessException.class)
    public R<Boolean> accessExceptionHandeler(AccessException exception) {
        if (exception instanceof VideoNotExistException) {
            return R.error(RCM.VIDEO_NOT_EXIST);
        }
        return R.error(RCM.COMMENT_NOT_EXIST);
    }

    @ExceptionHandler(SQLException.class)
    public R<Boolean> sqlExceptionHandeler(SQLException exception) {
        return R.error(RCM.SQL_ERROR);
    }
}
